<?php

declare(strict_types=1);

namespace app\model;

use think\Model;

/**
 * 
 *
 * @mixin \think\Model
 * @property int $id 自增id
 * @property string $dateymd 日期
 * @property int $income 收入。单位：分
 * @property int $payout 支出。单位：分
 */
class FinanceDaily extends Model
{
    /*
    dateymd 格式为 2021-11-11
    */
    public function increase($dateymd, $income, $payout, $profit)
    {
        return $this->where('dateymd', $dateymd)
                    ->inc('income', $income)
                    ->inc('payout', $payout)
                    ->inc('profit', $profit)
                    ->update();
    }

    /*
    减少
    */
    public function decrease($dateymd, $income, $payout, $profit)
    {
        return $this->where('dateymd', $dateymd)
                    ->dec('income', $income)
                    ->dec('payout', $payout)
                    ->dec('profit', $profit)
                    ->update();
    }

    public function initDaily($dateymd = '')
    {
        if (!$dateymd) {
            $dateymd = date('Y-m-d', strtotime('+1 day'));
        }

        return self::create(['dateymd' => $dateymd]);
    }
}
